import QtQuick 1.0

Item {
    id: unitSelectDialog
    width: 320
    height: 240
    clip: true
    smooth: true

    signal unitSelected(int index)

    Rectangle {
        id: roundedPanel
        width: 320
        height: 240
        anchors.centerIn: parent
        radius: 20
        opacity: 0.6
        smooth: true
        clip: true
        color: "gray"
    }

    Component {
        id: unitDelegate
        Rectangle {
            id: wrapper
            width: 30
            height: 30

            Text {
                anchors.centerIn: parent
                text: modelData
            }

            MouseArea {
                anchors.fill: parent
                onClicked: {
                    console.debug("GridView.currentIndex", index)
                    unitSelected(index)

                    unitSelectDialog.destroy()
                }
            }
        }
    }

    GridView {
        id: unitSelectGridView
        anchors.right: roundedPanel.right
        anchors.rightMargin: 8
        anchors.left: roundedPanel.left
        anchors.leftMargin: 8
        anchors.bottom: roundedPanel.bottom
        anchors.bottomMargin: 16
        anchors.top: roundedPanel.top
        anchors.topMargin: 16
        model: unitTypeSelectmodel

        delegate: unitDelegate
        preferredHighlightBegin: 0.5
        preferredHighlightEnd: 0.5
        highlightRangeMode: GridView.StrictlyEnforceRange
        highlightFollowsCurrentItem: true
        cellWidth: 40
        cellHeight: 40
    }
}
